package org.ytor.common.util.convert.converters;

import org.ytor.common.util.Numbers;
import org.ytor.common.util.convert.Converter;

/**
 * created by yangtong on 2025/8/13 19:19:53
 * <br/>
 */
public class NumberToBooleanConverter implements Converter<Number, Boolean> {
    @Override
    public Boolean convert(Number source) {
        if (source == null) {
            return null;
        }
        return Numbers.compare(source, 0) != 0;
    }

    @Override
    public Number reverseConvert(Boolean source) {
        if (source == null) {
            return null;
        }
        return source ? 1 : 0;
    }
}
